<?php
namespace App\Http\Resources\Trade\Shop;

use App\Http\Resources\ResourceCollection;
use App\Services\Utils\TencentYun\ImageService;

class DetailResource extends ResourceCollection
{

    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request            
     * @return array
     */
    public function toArray($request)
    {
        $data = $this->collection->shift();
        return self::makeDataDecode($data);
    }

    /**
     * 制作使用数据（一条）
     */
    public static function makeDataDecode($data)
    {
        // 手机号
        if (isset($data['contact_mobile']) && ! empty($data['contact_mobile']) && ! self::userEntity()->isValid()) {
            $data['contact_mobile'] = substr($data['contact_mobile'], 0, 3) . '****' . substr($data['contact_mobile'], 7, 4);
        }
        // 出售品种
        if (isset($data['kind_supply']) && ! empty($data['kind_supply'])) {
            $data['kind_supply'] = json_decode($data['kind_supply'], true);
        } else {
            $data['kind_supply'] = array();
        }
        // 求购品种
        if (isset($data['kind_demand']) && ! empty($data['kind_demand'])) {
            $data['kind_demand'] = json_decode($data['kind_demand'], true);
        } else {
            $data['kind_demand'] = array();
        }
        // 头像
        if (isset($data['avatar']) && ! empty($data['avatar'])) {
            $data['avatar_view'] = ImageService::makeDownloadUri($data['avatar']);
        } else {
            $data['avatar'] = '';
            $data['avatar_view'] = ImageService::makeDownloadDefaultUri();
        }
        // 跳转链接
        $data['uri'] = self::getListUri($data['id']);
        return $data;
    }

    /**
     * 店铺列表地址（出售、求购）
     *
     * @param $id 店铺ID            
     */
    public static function getListUri($id)
    {
        return [];
        // 'supply' => route('shopSupplyList', [
        // 'id' => $id
        // ]),
        // 'demand' => route('shopDemandList', [
        // 'id' => $id
        // ])
        
    }
}
